// 创建滚动控制器和状态管理类
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ScrollControllerX extends GetxController {
  final ScrollController scrollController = ScrollController();
  final isAtEnd = true.obs;

  @override
  void onInit() {
    super.onInit();
    scrollController.addListener(() {
      // 判断是否在末尾（即顶部，最新消息处）
      if (scrollController.position.pixels <=
          scrollController.position.minScrollExtent + 50) {
        isAtEnd.value = true;
      } else {
        isAtEnd.value = false;
      }
    });
  }

  @override
  void onClose() {
    scrollController.dispose();
    super.onClose();
  }
}
